import { Promise } from 'drunk-base';
import { HOST } from '../../../service/Config';
import { getJsonWithToken, postJsonWithToken, putJsonWithToken, deleteJsonWithToken } from '../../../service/HttpClient';
import { IMediaModel } from './MediaModel';
import { IPageMetaData } from '../../ListModel';

export function getMedia(id: string): Promise<IMediaModel> {
    return getJsonWithToken(`${HOST}/sys/meiti/${id}`);
}

export function getMediaList(page: number, size = 20): Promise<{ meta: IPageMetaData; data: IMediaModel[] }> {
    return getJsonWithToken(`${HOST}/sys/meiti?page=${page}&size=${size}`);
}

export function createMedia(data: IMediaModel): Promise<IMediaModel> {
    return postJsonWithToken(`${HOST}/sys/meiti`, data);
}

export function updateMedia(id: string, data: IMediaModel): Promise<IMediaModel> {
    return putJsonWithToken(`${HOST}/sys/meiti/${id}`, data);
}

export function deleteMedia(id: string) {
    return deleteJsonWithToken(`${HOST}/sys/meiti/${id}`);
}

export function search(name: string, startTime: number, endTime: number, page = 0, size = 20): Promise<{ data: IMediaModel[], meta: IPageMetaData }> {
    return getJsonWithToken(`${HOST}/sys/meiti?name=${name}&startTime=${startTime}&endTime=${endTime}&page=${page}&size=${size}`);
}
